package com.madou.dbtool.redis.panel.converter;

import com.madou.common.annotation.HideClass;
import com.madou.dbtool.ui.table.MColumn;
import com.madou.dbtool.ui.table.converter.CellDataConverter;
import com.madou.dbtool.ui.terminal.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;

/**
 * List<String>转换成命令格式的转换器
 * @author miukoo
 */
@HideClass
public class ListToCommandCellDataConverter implements CellDataConverter {

    public static final ListToCommandCellDataConverter INSTANCE = new ListToCommandCellDataConverter();

    /**
     * 转换为存储值
     * @param column
     * @param value
     * @return
     */
    @Override
    public Object encode(MColumn column, String value){
        return value;
    }

    /**
     * List<String>转换成命令格式的转换器
     * @param column
     * @param value
     * @return
     */
    @Override
    public Object decode(MColumn column, Object value){
        StringJoiner sb = new StringJoiner(" ");
        if(value instanceof List){
            List<Object> temp = (List<Object>) value;
            for (Object key : temp) {
                sb.add(key.toString());
            }
        }
        return sb.toString();
    }


}
